home *** CD-ROM | disk | FTP | other *** search
- ------------------------- ---- --- -- - -
- LL_COMM (R) Lord Logic's Comm Code
- Copyright (C) 1994 James P. Ketrenos
- ------------------------- ---- --- -- - -
-
- DATE: 8-27-94
-
- All C/C++ code is written in/for Watcom C/C++ v9.5+ using PWB.
- All ASM code is written in/for MASM v6.1 using PWB.
- Included makefile is for Watcom.
-
-
- ------------------------- ---- --- -- - -
- Files in this package
- ------------------------- ---- --- -- - -
- descript.ion 596 8-27-94 1:12p Norton DOS File Descriptions
- lcr.c 9386 8-27-94 1:12p Example Source using LL_COMM [C]
- lcr.exe 58786 8-27-94 1:12p LCR.C Executable
- lcr.h 5051 8-27-94 1:12p LCR.H Include file [C]
- lcr.obj 9025 8-27-94 1:12p LCR Compiled Object Code
- lcr.nfo 737 8-27-94 1:12p LCR Information
- ll_comm.asm 26730 8-27-94 1:12p Main package source [ASM]
- ll_comm.h 5038 8-27-94 1:12p LL_COMM Include file for .C [C]
- ll_comm.nfo 17374 8-27-94 1:12p LL_COMM Documentation
- ll_comm.obj 2093 8-27-94 1:12p LL_COMM Assembled Object Code
- ll_comm.txt 255 8-27-94 1:12p LL_COMM Brief Description
- ll_stat.h 313 8-27-94 1:12p Incremental Status Include [C]
- ll_stat.obj 1660 8-27-94 1:12p LL_STAT Compiled Object Code
- makefile 1112 8-27-94 1:12p Watcom C/C++ Makefile for LL_COMM
- register.nfo 5199 8-27-94 1:12p Registration Information
- 143,355 bytes
-
-
- ------------------------- ---- --- -- - -
- Prologue (yeah, whatever)
- ------------------------- ---- --- -- - -
- The LL_ prefix assigned to the archive name denotes that it is a library
- written by me. All code libraries that I release will use this naming
- convention.
-
- You'll notice that I code all of my hardware code in assembly to take
- advantage, as best as I can, of the hardware. The usage of those routines
- is normally from C as there is no point in coding memory management in
- assembly when the Watcom compiler optimizes so well.
-
- Code released so far: Code Provided:
- LL_KEY.ZIP ??k '94 Mult-key, buffered, keyboard IO ISR [C/ASM/32bit]
- LL_COMM.ZIP 42k '94 Low-level communication routines ISR [C/ASM/32bit]
- LL_LAND.ZIP 146k '93 Dot fractal landscape 3D viewer [C/ASM/16bit]
- LL_FRAC.ZIP 33k '93 Subdivision fractal scape generator [C/16-bit]
-
- To be released:
- LL_MCOMM.ZIP ??k '94 Low-level multi-port routines ISR [C/ASM/32bit]
- LL_TIME.ZIP ??k '94 Timer Reving Code ISR [C/ASM/32bit]
- LL_VRT.ZIP ??k '94 Tripple Buffering VRT ModeX Code ISR [C/ASM/32bit]
- LL_ENGIN.ZIP ??k '94 Low-level game engine [C/ASM/32bit]
- LL_VGA.ZIP ??k '94 Miscellaneous demo effects [C/ASM/32bit]
-
- ------------------------- ---- --- -- - -
- Purpose (more drudge)
- ------------------------- ---- --- -- - -
- Hey, I think I'll write a modem->modem game! Hey, there aren't any decent
- communication libraries out there. Perhaps I should write my own . . .
-
- Ok, there were some libraries out there, but none of them were written
- for Watcom, and all of the ones that I found crashed when trying to use
- my COM3 which is set to IRQ5 instead of IRQ4. So, I set off in search of
- information on coding the 8250 UART, found it, and coded this.
-
- This version (1.3) is the second public release of the routines. Version
- 2.0 may or may not come out. It depends on whether I get feedback on
- these routines.
-
-
- ------------------------- ---- --- -- - -
- Where's the ASM????
- ------------------------- ---- --- -- - -
- Its here in this release. I changed 4 lines in the DOCs, and decided
- to release this again with full source. Lucky you, eh?
-
- If you feel these routines deserve some monetary reward, feel free to send
- it to the address listed in "Contacting Me".
-
- If you know anyone looking to hire a coder, I am in the market. Resumes
- available upon request :)
-
-
- ------------------------- ---- --- -- - -
- Royalties
- ------------------------- ---- --- -- - -
- Please REGISTER.NFO for registration information.
-
- These routines represent a lot of my time (well, not a WHOLE lot, but
- enough that I deserve a little recognition maybe) Oh well.
-
- ------------------------- ---- --- -- - -
- Contacting Me
- ------------------------- ---- --- -- - -
- As these routines are my first communications routines, they are
- probably bug prone. I have tested them out as much as I can on my system,
- so if you find any bugs, please email them to me describing what the
- problem is.
-
- Bug reports are not limited to software problems. Misinformation in my
- docs are bugs as well--please report them. Thank you.
-
- If you have any questions about this code, or need help using it, let me
- know.
-
- The quickest way to reach me is to email me:
- ketrenoj@cs.pdx.edu
-
- You can snail mail me at: (before June 1995)
- James Ketrenos
- 885 SW 84th CT
- Portland, OR 97225
- USA
-
-
- ------------------------- ---- --- -- - -
- Thanks to . . .
- ------------------------- ---- --- -- - -
- Special thanks go out to the people behind Serial.FAQ as it was my sole
- source of reliable information. Without that FAQ, I would not have been
- able to write this code.
-
- You can obtain the FAQ from the newsgroup news.answers or archie for
- serial14 and you should find it there.
-
-
-
- ************************* **** *** ** * *
- Provided Routines
- ************************* **** *** ** * *
- NOTE: All routines written to take parameters via REGISTER.
- You must include LL_COMM.H or copy its contents into your
- code so that the arguments are parsed into the correct
- registers.
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- void ioClearRead(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine flushes the receiving buffer.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Example: /* If receive buffer has characters, then flush it */
- if (ioReadStatus(PortID))
- ioClearRead(PortID);
-
- See also: ioClearWrite(), ioReadByte, ioReadPacket(), ioReadStatus()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- void ioClearWrite(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine flushes the sending buffer.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Example: /* If send buffer has characters, then flush it */
- if (ioWriteStatus(PortID))
- ioClearWrite(PortID);
-
- See also: ioClearRead(), ioWriteByte, ioWritePacket(), ioWriteStatus()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioClosePort(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine closes communications with the passed port.
- It uninstalls the ISR and frees unecessary buffers.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Returns: 0 Success
- !0 Failure (passed PortID did not reference valid port)
-
- Example: /* Closes an open port */
- if (!ioClosePort(PortID)) {printf("Error!\n");}
-
- See also: ioOpenPort()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioGetBaud(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine determines the current baud-rate of
- the port.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Returns: Current baud rate. No error return (crash if PortID is bad)
-
- Example: /* Show the baud rate */
- printf("Rate: %d\n",ioGetBaud(PortID));
-
- See also: ioSetBaud()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioGetContol(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine gets the ports Line Control mode.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Returns: Current Line Control mode. Modes are combinations of the
- following:
-
- Line Control Modes:
- See ioSetControl()
-
- Example: /* Display BITS Mode */
- switch (ioGetControl(PortID)&(BITS_5|BITS_6|BITS_7|BITS_8))
- {
- case BITS_5:printf("5 BPW\n"); break;
- case BITS_6:printf("6 BPW\n"); break;
- case BITS_7:printf("7 BPW\n"); break;
- case BITS_8:printf("8 BPW\n"); break;
- default:printf("Tweakin mode... who knows...\n");
- }
-
- See also: ioSetControl, ioGetHandShake, ioGetStatus()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioGetHandShake(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine gets the ports handshaking mode.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Returns: Current HandShaking mode. Modes are combinations of the
- following:
-
- HandShaking Modes:
- See ioSetHandShake()
-
- Example: /* Check to see if in LOOPBACK */
- printf("LOOPBACK %s\n",
- (ioGetHandShake(PortID)&LOOPBACK) ? "SET" : "NOT SET");
-
- See also: ioSetHandShake, ioGetControl(), ioGetStatus()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- MODE ioGetMode(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- NOTE: Not yet available (scheduled for version 2.0)
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioGetStatus(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine gets the ports Modem/Line Status mode.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Returns: Current Modem/Line Status mode. Modes are combinations of the
- following:
-
- Line/Modem Status Modes:
- See LL_COMM.H and consult the Serial.FAQ
-
- Example: Haven't found any use for this one yet . . .
-
- See also: ioGetControl, ioGetHandShake
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- COMM ioOpenPort(int Base, int IRQ);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine, as it is named, opens communications with the
- port. It installs the ISR and sets various flags for use by
- the other routines.
-
- Pass: Base = Port base number
- IRQ = Interrupt ReQuest Number
-
- Returns: Type COMM which is used when calling the other routines
- to reference the opened port on success.
- NUL (0) on failure.
-
- Example: /* Initialize PORT 3f8 IRQ 4 (COM1 typically) */
- if (!(PortID=ioOpenPort(0x3f8, 4))) {printf("Error!\n");}
-
- The default settings for most systems is as follows:
- ioOpenPort(0x3f8, 4); // COM1
- ioOpenPort(0x2f8, 3); // COM2
- ioOpenPort(0x3e8, 4); // COM3
- ioOpenPort(0x2e8, 3); // COM4
-
- NOTE: As of this release, there is only single port code so you don't
- really need to keep the value returned.
-
- See also: ioClosePort(), ioSetBaud(), ioSetControl(), ioSetHandShake()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- char ioReadByte(COMM PortID);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine fetches a byte from the receiving buffer.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
-
- Returns: Next character in the buffer
- NUL (0) If buffer is empty
-
- Example: /* While receive buffer has characters, read it */
- while (ioReadStatus(PortID))
- printf("%c",ioReadByte(PortID));
-
- See also: ioClearRead(), ioWriteByte, ioReadPacket(), ioReadStatus()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioReadPacket(COMM PortID, PACKET &DataPacket);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- NOTE: Not yet available (scheduled for version 2.0)
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- void ioSetBaud(COMM PortID, int BaudRate);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine sets the port to a new baud-rate.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
- BaudRate= Legal baud rate (1-115200)
-
- Typical rates:
- 150, 300, 600, 1200, 2400, 4800, 9600,
- 19200, 28800, 38400, 57600, 115200
-
- Example: /* Set the baud rate */
- ioSetBaud(PortID, 57600);
-
- See also: ioGetBaud()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- void ioSetControl(COMM PortID, int ControlMode);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine sets the ports Line Control mode.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
- ControlMode = Bitfield for LC mode.
-
- Line Control Modes:
- Bits Per Word:
- BITS_5, BITS_6, BITS_7, BITS_8
-
- Stop Bits:
- STOP_1, STOP_2
-
- Parity:
- NO_PARITY, ODD_PARITY, EVEN_PARITY,
- MARK_PARITY, SPACE_PARITY
-
- Mode:
- NORMAL, BREAK
-
- You can | (OR) the above together to set different modes.
- BREAK sends a break signal to the port.
-
- Remember, when you are in a 5, 6, or 7 bit mode, only
- the first 5, 6, or 7 least significant bits are sent,
- regardless of what you send to the modem.
-
- For example, in BITS_6, if you send the '@' character,
- (which is 0x40 in HEX, or 01000000b in BINARY) then only
- the lower 6 bits will be sent making the sent byte have
- the value of 0x00 HEX, or 00000000b BINARY--in other words,
- it sent a NUL.
-
- Example: /* Set the line control to 8-n-1 */
- ioSetControl(PortID, BITS_8 | NO_PARITY | STOP_1);
-
- NOTE: BITS_5 in conjunctions with STOP_2 *might not* work with
- some hardware.
-
- See also: ioGetControl(), ioSetHandShake()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- void ioSetHandShake(COMM PortID, int ShakeMode);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine sets the ports handshaking mode.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
- ShakeMode = Bitfield for mode.
-
- HandShaking Modes:
- DTR, RTS, LOOPBACK
-
- You can | (OR) the above together to set different modes.
- LOOPBACK mode will not send or receive data through the port
- but will set the port so that whatever is sent out, is routed
- back in instead. CCAANN YYOOUU SSAAYY EECCHHOO??
-
- Example: /* Set the handshake to normal */
- ioSetHandShake(PortID, DTR | RTS);
-
- /* Set it to loopback */
- ioSetHandShake(PortID, LOOPBACK);
-
- See also: ioGetHandShake(), ioSetControl()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioSetMode(COMM PortID, MODE PacketMode);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- NOTE: Not yet available (scheduled for version 2.0)
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioWriteByte(COMM PortID, char Data);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- Purpose: This routine sends a to the receiving buffer.
-
- Pass: PortID = An open port ID (returned from ioOpenPort())
- Data = Character to send to the port
-
- Returns: !0 Successfully sent
- NUL (0) Failure (buffer full)
-
- Example: /* Send a string */
- char *x;
- for (x="Hello";*x;x++)
- ioWriteByte(PortID,*x);
-
- See also: ioClearWrite(), ioReadByte, ioWritePacket(), ioWriteStatus()
-
-
-
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- int ioWritePacket(COMM PortID, PACKET &DataPacket);
- ------------------- ---- --- -- - - - -- --- ---- ---------------
- NOTE: Not yet available (scheduled for version 2.0)
-